﻿Public Class FrmLoaiXe

    Private Sub GroupBox3_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox3.Enter

    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Hide()
        Me.Dispose()
    End Sub

    Private Sub btnNhapLai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNhapLai.Click
        btnSua.Text = "&Sửa"
        txtLoaiXe.Text = ""
    End Sub

    Private Sub btnTimKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimKiem.Click
        btnSua.Text = "&Sửa"
        dgvLoaiXe.DataSource = LoaiXe.timkiem(txtTuKhoa.Text)
    End Sub

    Private Sub btndaydu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndaydu.Click
        btnSua.Text = "&Sửa"
        dgvLoaiXe.DataSource = LoaiXe.dslx()
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        If txtLoaiXe.Text <> "" Then
            If Not LoaiXe.them(txtLoaiXe.Text) Then
                MsgBox("Bạn không thể thêm dữ liệu này", MsgBoxStyle.Critical, "Lỗi")
            End If
            dgvLoaiXe.DataSource = LoaiXe.dslx()
            btnNhapLai_Click(sender, e)
        Else
            MsgBox("Bạn cần nhập đầy đủ thông tin", MsgBoxStyle.Information, "Thông báo")
        End If
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        If btnSua.Text = "& Sửa" Then
            txtLoaiXe.Text = dgvLoaiXe.CurrentRow.Cells("TenLoai").Value
            btnSua.Text = "&Lưu"
        Else
            If Not LoaiXe.capnhat(dgvLoaiXe.CurrentRow.Cells("MaLoai").Value, txtLoaiXe.Text) Then
                MsgBox("Bạn không thể lưu dữ liệu", MsgBoxStyle.Critical, "Lỗi")
            End If
            dgvLoaiXe.DataSource = LoaiXe.dslx()
            btnNhapLai_Click(sender, e)

        End If
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        btnSua.Text = "&Sửa"
        If MsgBox("Bạn chắc chắn muốn xóa loại xe này chứ?", MsgBoxStyle.YesNo, "Thông báo") = MsgBoxResult.Yes Then
            If Not LoaiXe.xoa(dgvLoaiXe.CurrentRow.Cells("Maloai").Value) Then
                MsgBox("Bạn không thể xóa loại xe này", MsgBoxStyle.Critical, "Lỗi")
            End If
            dgvLoaiXe.DataSource = LoaiXe.dslx()
            btnNhapLai_Click(sender, e)
        End If
    End Sub
End Class